package com.xf.pub.exception.base;

import com.xf.pub.exception.ExceptionMessageFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class BaseException extends RuntimeException
{
  protected long errorCode;
  protected String status;
  protected final Log logger = LogFactory.getLog("servicelog");

  public BaseException()
  {
  }

  public BaseException(String message)
  {
    super(message);
  }

  public BaseException(long errorCode) {
    super(getMessage(errorCode));
    this.errorCode = errorCode;
  }

  public BaseException(String message, long errorCode) {
    super(message);
    this.errorCode = errorCode;
  }

  public BaseException(String message, Throwable cause) {
    super(message, cause);
  }

  public BaseException(Throwable cause) {
    super(cause);
  }

  public long getErrorCode() {
    return this.errorCode;
  }

  public void setErrorCode(long errorCode) {
    this.errorCode = errorCode;
  }

  public String getMessageAndErrorCode() {
    if (this.errorCode == -3439646184161935360L)
      return super.getMessage();

    return super.getMessage() + "<br/> 错误号:" + this.errorCode;
  }

  private static String getMessage(long errorCode)
  {
    String message;
    String isDefault = "false";

    String path = "serviceException.properties";
    if (Boolean.valueOf(isDefault).booleanValue() == true) {
      ExceptionMessageFactory.getInstance(true, ""); message = ExceptionMessageFactory.getExceptionMessage(String.valueOf(errorCode));
    }
    else {
      ExceptionMessageFactory.getInstance(false, path); message = ExceptionMessageFactory.getExceptionMessage(String.valueOf(errorCode));
    }

    return message;
  }

  public String getStatus() {
    return this.status;
  }

  public void setStatus(String status) {
    this.status = status;
  }
}